package com.ruoyi.system.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.BBiddingQy;
import com.ruoyi.system.mapper.BBiddingQyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BBiddingMapper;
import com.ruoyi.system.domain.BBidding;
import com.ruoyi.system.service.IBBiddingService;
import com.ruoyi.common.core.text.Convert;

/**
 * 投标保函Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-16
 */
@Service
public class BBiddingServiceImpl implements IBBiddingService 
{
    @Autowired
    private BBiddingMapper bBiddingMapper;
    @Autowired
    private BBiddingQyMapper bBiddingQyMapper;

    /**
     * 查询投标保函
     * 
     * @param id 投标保函主键
     * @return 投标保函
     */
    @Override
    public BBidding selectBBiddingById(Long id)
    {
        return bBiddingMapper.selectBBiddingById(id);
    }

    /**
     * 查询投标保函列表
     * 
     * @param bBidding 投标保函
     * @return 投标保函
     */
    @Override
    public List<BBidding> selectBBiddingList(BBidding bBidding)
    {
        return bBiddingMapper.selectBBiddingList(bBidding);
    }

    /**
     * 新增投标保函
     * 
     * @param bBidding 投标保函
     * @return 结果
     */
    @Override
    public int insertBBidding(BBidding bBidding)
    {
        bBidding.setCreateTime(DateUtils.getNowDate());
        return bBiddingMapper.insertBBidding(bBidding);
    }

    /**
     * 修改投标保函
     * 
     * @param bBidding 投标保函
     * @return 结果
     */
    @Override
    public int updateBBidding(BBidding bBidding)
    {
        bBidding.setUpdateTime(DateUtils.getNowDate());
        return bBiddingMapper.updateBBidding(bBidding);
    }

    /**
     * 批量删除投标保函
     * 
     * @param ids 需要删除的投标保函主键
     * @return 结果
     */
    @Override
    public int deleteBBiddingByIds(String ids)
    {
        return bBiddingMapper.deleteBBiddingByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除投标保函信息
     * 
     * @param id 投标保函主键
     * @return 结果
     */
    @Override
    public int deleteBBiddingById(Long id)
    {
        return bBiddingMapper.deleteBBiddingById(id);
    }

    /**
     * 新增投标保函赫企业
     *
     * @param bBidding 投标保函
     * @return 结果
     */
    @Override
    public int insertBBiddingAndQiye(BBidding bBidding) {
        int a = bBiddingMapper.insertBBidding(bBidding);
        if (a>0){
            List<BBiddingQy> bBiddingQyList = JSONArray.parseArray(bBidding.getQiyeData(), BBiddingQy.class);
            for (int i=0;i<bBiddingQyList.size();i++){
                BBiddingQy bBiddingQy = bBiddingQyList.get(i);
                bBiddingQy.setBidId(bBidding.getId());
                //增加企业
                bBiddingQyMapper.insertBBiddingQy(bBiddingQy);
                System.out.println(bBiddingQyList.get(i));
            }
        }

        return a;
    }
}
